#include "stdio.h"
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

#define FIFO "./fifo"

int main() {
    int ret = mkfifo(FIFO, 0644);
    if (ret < 0) {
        perror("mkfifo");
    }
    int fd = open(FIFO, O_RDONLY);
    if (fd < 0) {
        perror("open");
        return 1;
    }
    
    char buf[64] = {0};

    while (1) {
        ssize_t s = read(fd, buf, sizeof(buf)-1);
        if (s > 0) {
            buf[s] = 0;
            printf("parent get message from client#: %s", buf);
        }else if(s == 0) {
            printf("client quit\n");
            break;
        }else {
            break;
        }
    }
    close(fd);
    return 0; 
}
